<!--{template lyear:header_simple}-->
<div class="container-fluid">
  <div class="card">
    <div class="card-body">
        <ul class="nav nav-pills">
          <li class="nav-item"><a class="nav-link" href="{MOD_URL}"> {lang my_clouds}</a></li>
          <li class="nav-item"> <a class="nav-link" href="{MOD_URL}&op=addcloud">{lang add_clouds}</a> </li>
          <li class="nav-item"> <a class="nav-link active" href="{MOD_URL}&op=oauth&bz=ALIOSS">{lang add_ali_cloud}</a> </li>
        </ul>
    </div>
  </div>
  <div class="card">
        <div class="card-body">
            <form name="aliform" class="form-horizontal" action="{MOD_URL}&op=oauth" method="post" onsubmit="return validate(this)">
              <input type="hidden" name="alisubmit" value="true" />
              <input type="hidden" name="bz" value="ALIOSS" />
              <input type="hidden" name="formhash" value="{FORMHASH}" />
              <div class="row mb-3">
                <label class="col-sm-2" for="access_id">Access Key ID</label>
                <div class="col-sm-10">
                  <input type="text" id="access_id" class="form-control" name="access_id" autocomplete="off" value="$ali[access_id]" onblur="if(this.value==''){jQuery(this).addClass('is-invalid');}else{jQuery(this).removeClass('is-invalid');getBucket();}">
                  <span class="form-text">{lang oauth_ALIOSS_ALY_storage}Access Key ID</span> 
                </div>
              </div>
              <div class="row mb-3">
                <label class="col-sm-2" for="access_key">Access Key Secret</label>
                <div class="col-sm-10">
                  <input type="password" class="form-control" id="access_key" name="access_key" autocomplete="off" value="$ali[access_id]" onblur="if(this.value==''){jQuery(this).addClass('is-invalid');}else{jQuery(this).removeClass('is-invalid');getBucket();}">
                  <span class="form-text">{lang oauth_ALIOSS_ALY_storage}Access Key Secret</span> 
                </div>
              </div>
              <div class="row mb-3">
                <label class="col-sm-2"><a href="javascript:;" onclick="getBucket()">{lang oauth_ALIOSS_click_gain}</a></label>
                <div class="col-sm-10">
                  <select id="bucket" name="bucket" class="form-select" onchange="setBucketHost()"></select>
                  <span class="form-text">{lang oauth_ALIOSS_bucket}</span> 
                </div>
              </div>
              <div class="row mb-3">
                <label class="col-sm-2" for="hostname">
                  <a id="hostname_dropmenu" role="button" data-toggle="dropdown" href="#" aria-expanded="false" class="btn btn-primary dropdown-toggle">{lang select_node_address} </a>
                  <ul id="menu3" class="dropdown-menu" role="menu" aria-labelledby="drop6" style="max-height:300px;overflow-y:auto;">
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-hangzhou.aliyuncs.com" onclick="selectHostName(this);return false;">{lang oauth_ALIOSS_node1}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-hangzhou-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node2}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-qingdao.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node3}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-qingdao-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node4}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-beijing.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node5}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-beijing-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node6}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-hongkong.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node7}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-hongkong-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node8}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-shenzhen.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node9}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-shenzhen-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node10}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-shanghai.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node11}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-cn-shanghai-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node12}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-us-west-1.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node13}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-us-west-1-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node14}</a></li>
                    <li role="presentation" class="dropdown-divider"></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-ap-southeast-1.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node15}</a></li>
                    <li role="presentation"><a role="menuitem" class="dropdown-item" tabindex="-1" href="javascript:;" hostname="oss-ap-southeast-1-internal.aliyuncs.com" onclick="document.getElementById('hostname').value=jQuery(this).attr('hostname');return false;">{lang oauth_ALIOSS_node16}</a></li>
                  </ul>
                </label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="hostname" name="hostname" autocomplete="off" value="$ali[hostname]" onblur="if(this.value==''){jQuery(this).addClass('is-invalid');}else{jQuery(this).removeClass('is-invalid');}">
                  <span class="form-text">{lang oauth_ALIOSS_node17}</span> 
                </div>
              </div>
              <dl class="mb-3 d-grid">
                  <input type="submit" class="btn btn-primary btn-round bodyloading" value="{lang add}">
              </dl>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
	function setBucketHost() {
		jQuery('#hostname').val('');
		jQuery("#bucket").removeClass('is-invalid');
	}

	function selectHostName(obj) {
		jQuery('#hostname').val(jQuery(obj).attr('hostname'));
		jQuery("#hostname").removeClass('is-invalid');
		jQuery('#hostname_dropmenu').html(jQuery(obj).html() + '');
	}

	function getBucket() {
		var id = jQuery("#access_id").val();
		var key = jQuery("#access_key").val();
		if(id == '' || key == '') {
			return;
		}
		jQuery.getJSON('{MOD_URL}&op=oauth&do=getBucket', { id: id, key: key }, function(json) {
		    console.log(json);
			if(json.length > 0) {
				var html = '';
				for(var i in json) {
					html += '<option value="' + json[i] + '" >' + json[i] + '</option>';
				}
				console.log(html);
				jQuery('#bucket').html(html);
			}
		});

	}

	function validate(form) {
		if(jQuery("#access_id").val() == '') {
			jQuery("#access_id").addClass('is-invalid');
			return false;
		} else if(jQuery("#access_key").val() == '') {
			jQuery("#access_key").addClass('is-invalid');
			return false;
		} else if(jQuery("#bucket").val() == '') {
			jQuery("#bucket").addClass('is-invalid');
			return false;
		} else if(jQuery("#hostname").val() == '') {
			jQuery("#hostname").addClass('is-invalid');
			return false;
		}
		return true;
	}
</script> 
<!--{template lyear:footer}-->